home *** CD-ROM | disk | FTP | other *** search
-
-
-
- SH ST-UNIX User's Manual SH
-
-
-
- COMMAND
- sh - comamnd line interpreter
-
- FORMAT
- sh [ -enstuvx ] [ file ] ...
-
- DESCRIPTION
- _✓S_✓h is a command line interpreter nterface to GEMDOS. It per-
- mits the typing of commands from the keyboard and replaces
- the GEM desktop.
-
- The shell provides features found in programming languages
- such as varaibles and loops.
-
- OPTIONS
- -e if the shell is not in interactive mode (ie. commands
- are being read from a file) the shell exits if a com-
- mand fails.
-
- -n commands are read, and variable substitution takes
- place, but the commands are not executed.
-
- -t shell exits after reading and executing one command.
-
- -u treat unset variables as an error when substituting.
-
- -v print input lines as they are read.
-
- -x print the command line before it is executed.
-
- - turn off -x and -v options
-
- COMMANDS
- Command consist of a sequence of words. The first word is
- the command name and the tail is the arguments to the com-
- mand. More than one command can be placed on a line, a ';'
- separates the commands.
-
- Conditional execution of commands can be formed be separat-
- ing the command with the operators '&&' and '||', for 'and'
- and 'or' resepctively. Logical 'and', if the execution of
- the first command is successful the second one proceeds,
- else the rest of the command line is terminated. Logical
- 'or', the second command is executed only if the first one
- fails.
-
- REPETITION AND CONDITIONAL EXECUTION OF COMMANDS
- A number of inbuilt commands are provided for performing
- loops and conditional execution. Loops
-
- Three types of loop control are provided.
-
-
-
-
- Printed 10/April/1987 1st April 1987 1
-
-
-
-
-
-
- SH ST-UNIX User's Manual SH
-
-
-
- for name [in word ...] do command-list done
-
- For every iteration of the loop, name is setto the next
- word in the word list. If the 'in' command and word
- list are ommited the variable '$@' (see later) is used.
- Execution of the command list terminates when ther are
- no more words in the list.
-
- This example displays the names of all files with the
- extension '.c':
-
-
- for i in *.c
- do
-
- echo File: $i
-
- done
-
- while command-list1 [ do command-list2 ] done
-
- The while command executes command-list1 and if the
- last command in the list returns true command-list2 is
- executed. Execution continues until command-list1
- fails.
-
- The following example asks the user for a name of a
- file to edit and then invokes the editor. When the edit
- is complete the user is asked for another file name.
- This continues indefinitly.
-
-
- while true
- do
-
- echo -n File to edit
- read filename
- edit $filename
-
- done
-
- if command-list1 then list1 [ elif command-list2 then list2
- ] ... [ else list ] fi
-
- If executes command-list1, if the last command in the
- list returns true then list1 is executed. If the com-
- mand fails control passes to elif, then, or if returns.
-
- The example shows the printing of a filename is the
- file exists.
-
-
-
-
-
- Printed 10/April/1987 1st April 1987 2
-
-
-
-
-
-
- SH ST-UNIX User's Manual SH
-
-
-
- echo -n File /?
- read filename
- if test -f $filename
- then
-
- echo $filename
-
- done
-
- case word in [ pattern ) command-list ;; ] ... esac
-
- The case command executes the command-list associated
- withthe matching of word with pattern
-
- The example shows how to change the name of a file.
-
-
- echo -n File /?
- read filename
- case $filename in
-
- a.c) filename=b.c;;
- c.c) filename=b.c;;
-
- esac
-
- VARIABLES
- The shell provides variables as in conventional languages.
- Variables are assigned a value with the '=' operator. The
- varaible name is composed of a sequence of letters, digits,
- or characters * @ # ? $ !.
-
-
- var-name=string
-
-
-
- Variable substitution on the command line is performed using
- the '$' operator.
-
-
- $variable=a long string
- $echo ${variable}
- a long string
- $
-
-
-
- The '{' and '}' braces in the example may be ommited if spe-
- cial characters are not contained in the variable name. The
- special characters are discussed.
-
-
-
-
- Printed 10/April/1987 1st April 1987 3
-
-
-
-
-
-
- SH ST-UNIX User's Manual SH
-
-
-
- ${varname-word} If the variable is set (has been
- assigned a value) it's value is substituted, else the
- word is substituted.
-
- ${varname=word} If the variable is not set, it is set
- to word, and it's value substituted.
-
- ${varname?word} If the variable is not set the word is
- printed and the shell exits.
-
- ${varname+word} If the variable is set, word is substi-
- tuted, otherwise nothing is substituted.
-
- There are a number of internal parameters to the shell.
- These can not be changed by assignment.
-
- number The shell argument corresponding to number. For
- example $0 is the command name 'sh'.
-
- # The number of parameters to the shell.
-
- - The options supplied to the shell.
-
- ? The value of the error returned by the last command
- executed.
-
- The shell has defined some variables which are accessable to
- the user.
-
- HOME The default directory used by 'cd' when no argu-
- ment is supplied.
-
- PATH The search path used in lokating a command to be
- executed.
-
- PS1 PS2 The prompt string, PS2 is used when a partialy
- completed command is typed.
-
- QUOTING OF STRINGS ON THE COMMAND
- The interpretation of characters in the command line can be
- changed by the use of quotes. The quotes ' and " are passed
- unaltered to the command for it's interpretation. The '
- quote passes everything unaltered, but the " quote inter-
- prets $ as variable expansion. be not interpreted. This is
- useful for inserting special characters, syuch as '$', into
- the command line, and continueing very long lines (as the
- newline character is ignored). A string in the backquotes ``
- is executed as a command and the output of that command
- inserted into the command line. For example:
-
- pathname=`pwd`
-
-
-
-
- Printed 10/April/1987 1st April 1987 4
-
-
-
-
-
-
- SH ST-UNIX User's Manual SH
-
-
-
- set the variable 'pathname' to the current directory.
-
- INPUT-OUTPUT REDIRECTION
- The input and output of a command can be redirected using
- the operators
-
- <filename makes the command take it's input from the
- file 'filename'.
-
- >filename will cause the command to send its output to
- the file 'filename' rather than a file.
-
- command1 | command2 pipelines of commands can be formed
- using the '|' operator. A pipline allows the output of
- one command to form the input of another. For example,
- command1 will send it's output to form the input for
- command2.
-
- COMMAND EXECTION
- When the command line has be processed (variable substitu-
- tion has taken place) then command is executed. The variable
- PATH is used in locating the position of the command on the
- disc. The pathnames in the variable list are searched for
- the command, and if it is found the command is executed. The
- separator ':' is used to separate pathnames in the list.
-
- Before the command is executed it's type is checked. If the
- file is a binary then the command, arguments, and environ-
- ment are passed to GEMDOS for execution. If the file is
- text, the shell takes the lines as input and executes them.
-
- The environment is made up of the 'exported' variables in
- the shell. The format of the environment passed to the com-
- mand is a list of null terminated strings which is ter-
- minated by a null.
-
- COMMAND HISTORY AND COMMAND LINE EDITING
- The history mechanism allows previously typed commands to be
- used without having to retype the whole line again. If the
- UP-ARROW key is pressed once the previous command type is
- displayed. The key may be pressed upto the first command
- typed. Pressing the DOWN-ARROW key lets you step forward
- from the current command typed.
-
- Command lines may be edited using the left and right arrow
- keys. Moving the cursor over a previously typed character
- allows text to be inserted before the cursor.
-
- There are a number of editing keys available:
-
- ^I - TAB inserts spaces upto the next tab position in
- the line. Tabs are placed at every eight characters.
-
-
-
- Printed 10/April/1987 1st April 1987 5
-
-
-
-
-
-
- SH ST-UNIX User's Manual SH
-
-
-
- ^U deletes the whole line.
-
- ^W deletes the previous word.
-
- BS - backspace deletes the character before the cursor.
-
- DEL deletes the character under the cursor.
-
- INBUILT SHELL COMMANDS
- The following comamnds a special to the shell and are exe-
- cuted internaly.
-
- : This command does nothing except evaluate it's argu-
- ments. It can be used as a comment.
-
- break Will cause termination of a for or while loop.
-
- clear Clears the screen.
-
- continue Execution continues on the next iteration of
- the for or while loop.
-
- cd pathname The working directory is changed to path-
- name.
-
- eval command Command is executed
-
- exec command Same as eval.
-
- exit [error] The shell is terminated. Error is a number
- which is returned if defined, default is zero. The
- shell can also be terminated by typing ^D to the
- prompt.
-
- export [varname ] The variable is marked for exporta-
- tion to an executing command. If no variable is sup-
- plied a list of the exportable variables is displayed.
-
- history Displays the history of command lines for the
- last 20 commands executed.
-
- read name ... A line is read from the keyboard and
- it's value assigned to the variable. If more than one
- variable is specified each word is assigned to each
- variable, with any remaining words assigned to the last
- varibale.
-
- readonly [ varname ] The variable is marked as
- readonly. It's value cannot be changed by subsequent
- assignment. If no variable is supplied a list of
- readonly variables is displayed.
-
-
-
-
- Printed 10/April/1987 1st April 1987 6
-
-
-
-
-
-
- SH ST-UNIX User's Manual SH
-
-
-
- set [-entuvx] Allows the setting of argument flags.
- These are defined at the beginning of the document. If
- no argument is supplied the values of the variables are
- displayed.
-
- shift The shell arguments are renamed. For example
- argument $2 becomes $1
-
- times command The execution time for command is
- displayed.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Printed 10/April/1987 1st April 1987 7
-
-
-
-